﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.UI.DataVisualization.Charting;


namespace ChartsDemo
{
    public class ChartHelper
    {

        private int Width { get; set; }
        private int Height { get; set; }

        private readonly Chart _chartInstance;

        public ChartHelper(int width, int height,string name)
        {

            _chartInstance = new Chart();
            _chartInstance.Height = Height = width;
            _chartInstance.Width = Width = height;
            _chartInstance.Titles.Add(name);
            ChartType = SeriesChartType.Column;//默认是柱状图
        }

        public Chart GetChartInstance()
        {
            return _chartInstance;
        }

        public ChartArea ChartArea { get; set; }

        public List<Series> Series { get; set; }
        /// <summary>
        /// 图表类型
        /// </summary>
        private SeriesChartType ChartType { get; set; }
        /// <summary>
        /// 坐标轴的颜色
        /// </summary>
        public Color LineColor { get; set; }
        public Legend Legend { get; set; }
        /// <summary>
        /// 表格线的颜色
        /// </summary>
        public Color MajorGridLineColor { get; set; }

        public Chart InitConfig()
        {
            if (ChartArea == null)
            {
                ChartArea = new ChartArea();
            }

           
            _chartInstance.ChartAreas.Add(ChartArea);

            if (!Series.Any())
            {
                return null;
            }
            if (Legend != null)
            {
                _chartInstance.Legends.Add(Legend);
            }
            foreach (var s in Series)
            {
                s.IsValueShownAsLabel = true;
                s["PixelPointWidth"] = "40";
                //像素点深度
                s["PixelPointDepth"] = "80";
                //像素点间隙深度
                s["PixelPointGapDepth"] = "10";
                s.BorderWidth = 2;
                _chartInstance.Series.Add(s);
            }

            return _chartInstance;

        }
    }
}
